<?php

namespace app\model;

class OrderLogModel extends BaseModel
{
    protected $name = 'dingdan_log';


    public const REJECT = 100; //驳回
    public const APPROVE = 200; //通过
    public const REVOKE = 300;//撤销
    public const INITIATE_APPROVAL = 400;//发起审批


    public const TYPE_ARRAY = [
        self::REJECT => '驳回',
        self::APPROVE => '通过',
        self::REVOKE => '撤销',
        self::INITIATE_APPROVAL => '发起审批',
    ];

    /**
     * Notes: 销售订单审核日志
     * User: chenLei
     * Date: 9/14/25
     * @param $params
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function list($params)
    {
        $where = [];
        $where[] = ['dingdan_id', '=', $params['dingdan_id']];


        return $this->where($where)->order('id desc')->select()
            ->each(function ($item) {
                $item['status_text'] = self::TYPE_ARRAY[$item['status']] ?? '';
                $user = UserModel::where('id', $item['user_id'])->field('id,username,realname')->find();
                $item['user'] = $user;
                $item['department'] = UserDepartmentModel::where('id',$item['department_id'])->find();

            })
            ->toArray();
    }
}